package com.eig.courseweb.controller;

import com.eig.common.entity.course.Video;
import com.eig.common.vo.Result;
import com.eig.courseweb.service.impl.VideoServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.annotation.Resource;

/**
 * @author ：StudentLsj（李世界）
 * @date ：Created in 2023/01/12 下午 09:43
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("core/video")
@Api(tags = "初始化数据课程")
@EnableSwagger2
public class VideoController {


    @Resource
    private VideoServiceImpl videoService;

    @GetMapping("/findAllVideo/{chapterId}")
    @ApiOperation(value = "chapterId")
    public Result findAllVideo(@PathVariable String chapterId) {
        return videoService.findAllVideo(chapterId);
    }

    @PutMapping("/insertVideo")
    @ApiOperation(value = "添加")
    public Result insertVideo(@RequestBody Video video) {
        //Video(id=null, courseId=1613520683629805568, chapterId=1613529553588715520, title=2222, videoSourceId=https://xhlsj0102.oss-cn-hangzhou.aliyuncs.com/io20230112215345701, videoOriginalName=https://xhlsj0102.oss-cn-hangzhou.aliyuncs.com/io20230112215334340, sort=1, playCount=null, isFree=false, duration=0.0, status=null, size=null, version=null, gmtCreate=null, gmtModified=null)
        return videoService.insertVideo(video);
    }
    @PostMapping("/updateVideo")
    @ApiOperation(value = "修改")
    public Result updateVideo(@RequestBody Video video) {
        //Video(id=null, courseId=1613520683629805568, chapterId=1613529553588715520, title=2222, videoSourceId=https://xhlsj0102.oss-cn-hangzhou.aliyuncs.com/io20230112215345701, videoOriginalName=https://xhlsj0102.oss-cn-hangzhou.aliyuncs.com/io20230112215334340, sort=1, playCount=null, isFree=false, duration=0.0, status=null, size=null, version=null, gmtCreate=null, gmtModified=null)

        return videoService.updateVideo(video);
    }
    @PostMapping("/queryAllVideoByCourseId/{id}")
    @ApiOperation(value = "根据课程id获取所有的章节的视频")
    public Result queryAllVideoByCourseId(@PathVariable String id) {
        return videoService.queryAllVideoByCourseId(id);
    }
    @DeleteMapping("/deleteById/{id}/{sort}/{chapterId}")
    @ApiOperation(value = "删除")
    public Result deleteById(@PathVariable String id,@PathVariable int sort,@PathVariable String chapterId) {
        return videoService.deleteById(id,sort,chapterId);
    }

}
